package com.educate.device.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.educate.common.web.R;
import com.educate.device.model.bo.UpdatePackBO;
import com.educate.device.rpc.api.UpdatePackService;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("updatePack")
public class UpdatePackController {

    @Reference(version = "${api.service.version}",
            application = "${dubbo.application.id}",
            url = "${dubbo.application.url}")
    private UpdatePackService updatePackService;

    @PostMapping(value = "/create")
    public R create(@RequestBody UpdatePackBO bo) {
        updatePackService.create(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete")
    public R delete(@RequestBody UpdatePackBO bo) {
        updatePackService.delete(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete/{updatePackId}")
    public R delete(@PathVariable String updatePackId) {
        updatePackService.delete(updatePackId);
        return R.ok();
    }

    @PostMapping(value = "/detail/{updatePackId}")
    public R<UpdatePackBO> detail(@PathVariable String updatePackId) {
        UpdatePackBO bo = updatePackService.detail(updatePackId);
        return R.ok(bo);
    }

    @PostMapping(value = "/detail")
    public R<UpdatePackBO> detail(@RequestBody UpdatePackBO bo) {
        UpdatePackBO detail = updatePackService.detail(bo);
        return R.ok(detail);
    }

    @PostMapping(value = "/update")
    public R<UpdatePackBO> update(@RequestBody UpdatePackBO bo) {
        updatePackService.update(bo);
        return R.ok();
    }

    @PostMapping(value = "/query")
    public R<Page<UpdatePackBO>> query(@RequestBody UpdatePackBO bo) {
        Page<UpdatePackBO> result = updatePackService.query(bo, bo.pageable());
        return R.ok(result);
    }

    @PostMapping(value = "/list")
    public R<List<UpdatePackBO>> list(@RequestBody UpdatePackBO bo) {
        List<UpdatePackBO> result = updatePackService.list(bo);
        return R.ok(result);
    }

}
